package com.greensecurity.sim.repository;

import com.greensecurity.sim.entity.GreenLand;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface GreenLandRepository extends JpaRepository<GreenLand, Long> {

    @Query(value = "SELECT * FROM green_land LIMIT 5",nativeQuery = true)
    List<GreenLand> findGreenLandLimit();

    @Transactional//注解在代码执行出错的时候能够进行事务的回滚。
    @Modifying
    @Query(value = "DELETE FROM user_green_lands WHERE green_lands_id = ?1 ",nativeQuery = true)
    void deleteGreendKey(String id);


}
